package com.ljb.main;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hikvision.vmsnetsdk.CameraInfo;

import java.util.List;

/**
 * Created by ljb on 2017/6/1.
 */

public class CameraAdapter extends BaseAdapter {

    private List<CameraInfo> mCameraInfos;
    private LayoutInflater mInflater;

    public CameraAdapter(Context c, List<CameraInfo> cameraInfos) {
        mInflater = LayoutInflater.from(c);
        mCameraInfos = cameraInfos;
    }

    @Override
    public int getCount() {
        return mCameraInfos.size();
    }

    @Override
    public CameraInfo getItem(int position) {
        return mCameraInfos.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_region, parent, false);
        }
        CameraInfo cameraInfo = getItem(position);

        TextView tv_camera = (TextView) convertView.findViewById(R.id.tv_region);
        tv_camera.setText(cameraInfo.name);

        String cameraID = cameraInfo.cameraID;
        String deviceID = cameraInfo.deviceID;
        List<CameraInfo> cameraInfoList = DataTemp.init().cameraInfoList_my;
        for (CameraInfo info : cameraInfoList) {
            if (TextUtils.equals(cameraID, info.cameraID) && TextUtils.equals(deviceID, info.deviceID)) {
                convertView.setBackgroundColor(Color.parseColor("#33B5E5"));
                return convertView;
            }
        }
        convertView.setBackgroundColor(Color.WHITE);

        return convertView;
    }
}
